<template>
  <div class="components-input-demo-presuffix">
    <!---->
    <a-input @click="openModal"  placeholder="请点击选择服务" v-model="serviceId" readOnly :disabled="disabled">
      <a-icon slot="prefix" type="cluster" title="部门选择控件"/>
      <a-icon v-if="serviceIds" slot="suffix" type="close-circle" @click="handleEmpty" title="清空"/>
    </a-input>

    <j-select-capability-modal
      ref="innerDepartSelectModal"
      :modal-width="modalWidth"
      :multi="multi"
      :rootOpened="rootOpened"
      :depart-id="serviceIds"
      @ok="handleOK"
      @initComp="initComp"/>
  </div>
</template>

<script>


  import JSelectCapabilityModal from './modal/JSelectCapabilityModal'

  export default {
    name: 'JSelectCapability',
    components:{
      JSelectCapabilityModal
    },
    props:{
      modalWidth:{
        type:Number,
        default:1200,
        required:false
      },
       msg:{
        type:String,
        required:false
      },
      multi:{
        type:Boolean,
        default:false,
        required:false
      },
      rootOpened:{
        type:Boolean,
        default:true,
        required:false
      },
      // value:{
      //   type:String,
      //   required:false
      // },
      disabled:{
        type: Boolean,
        required: false,
        default: false
      },
      // 自定义返回字段，默认返回 id
      customReturnField: {
        type: String,
        default: 'id'
      }
    },
    data(){
      return {
        visible:false,
        confirmLoading:false,
        serviceId:'',
        serviceIds:'',

      }
    },
    mounted(){
      
      this.serviceId= this.$route.query.serviceId?this.$route.query.serviceId:this.msg
    },
    watch:{
      msg(val){
        
        this.serviceId=val
        
      }
    },
    methods:{
      initComp(departNames){
        
        this.departNames = departNames
      },
      openModal(){
        this.$refs.innerDepartSelectModal.show()
      },
      handleOK(val) {
        
         this.serviceId = val
         this.$emit("change", val)
        
      },
      
      getDepartNames(){
        return this.departNames
      },
      handleEmpty(){
        this.handleOK('')
      },
       initDictConfig(){
      },
      
    },
    model: {
      prop: 'value',
      event: 'change'
    }
  }
</script>

<style scoped>
  @import '~@assets/less/common.less';

  .components-input-demo-presuffix .anticon-close-circle {
    cursor: pointer;
    color: #ccc;
    transition: color 0.3s;
    font-size: 12px;
  }
  .components-input-demo-presuffix .anticon-close-circle:hover {
    color: #f5222d;
  }
  .components-input-demo-presuffix .anticon-close-circle:active {
    color: #666;
  }
</style>